home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / UUPC3 / MAC_SPEC / UNIX_LIB / MKDIR.C < prev    next >
C/C++ Source or Header  |  1989-10-30  |  2KB  |  105 lines

  1. #ifdef THINK_C
  2. # include "unixlibproto.h"
  3. #endif THINK_C
  4.  
  5. #ifndef  THINK_C
  6. #include <errno.h>
  7. #include <memory.h>
  8. #include <pb.h>
  9. #include <aztec/shell.h>
  10.  
  11. #define _DEBUG
  12. #include <max/debug.h>
  13. #ifdef TEST
  14. #include <stdio.h>
  15. #endif
  16.  
  17. #ifndef NULL
  18. #define NULL 0L
  19. #endif
  20.  
  21. mkdir( path )
  22. char * path;
  23. {
  24.  
  25.     char npath[255];
  26.     CInfoPBRec cpb;
  27.     int err;
  28.     register char * cp;
  29.  
  30.  
  31.     /* fix name, and get volume reference number */
  32.  
  33.  
  34.     cpb.ioVRefNum =  hfixnam( path, npath );
  35.  
  36. #ifdef TEST
  37.     fprintf( stderr, "opendir: %s\n", npath );
  38. #endif
  39.  
  40.     cpb.ioNamePtr = ctop( npath );
  41.     cpb.ioFDirIndex = 0;
  42.     cpb.u.di.ioDrDirID = 0L;
  43.     if ((err = PBDirCreate( &cpb, 0 )) != 0 ) {
  44. #ifdef TEST
  45.         fprintf( stderr, "setdir: PBDirCreateGetCatInfo %d\n", err );
  46. #endif
  47.         return ENOENT;
  48.     }
  49.  
  50.  
  51.  
  52.     return 0;
  53.  
  54. }
  55.  
  56. #ifdef TEST
  57. main()
  58. {
  59.     char command[100];
  60.  
  61.     gets( command );
  62.     fprintf( stderr, "%d\n", mkdir( command ));
  63. }
  64.  
  65. #endif
  66. #else    THINK_C
  67. # include    <string.h>
  68. #ifndef NULL
  69. #define NULL 0L
  70. #endif
  71.  
  72. OSErr mkdir( path )
  73. char * path;
  74. {
  75.     HParamBlockRec    pb;
  76.     WDPBRec            wd;
  77.     char            npath[255];
  78.     int                idx, len;
  79.     
  80.     cnvMac(path, npath);        /* convert to Mac-style pathname */
  81.     if (strchr(npath, ':') == NULL || *npath == ':') {
  82.         /* relative to the current working directory */
  83. #ifdef THINK_C
  84.         memset((char *)(&wd), (int)NULL, (size_t)sizeof(wd));
  85. #else THINK_C
  86.         repmem((char *)&wd, "", 1, sizeof(wd));
  87. #endif THINK_C
  88.         /* get parent dir id */
  89.         if (PBHGetVol(&wd, false) != noErr) {
  90.             return -1;
  91.         }
  92.         pb.fileParam.ioDirID = wd.ioWDDirID;
  93.     }
  94.     else {
  95.         /* absolute pathname */
  96.         pb.fileParam.ioDirID = 0;
  97.     }
  98.     CtoPstr(npath);
  99.     pb.fileParam.ioNamePtr = (StringPtr)npath;
  100.     pb.fileParam.ioVRefNum = 0;
  101.     pb.fileParam.ioCompletion = NULL;
  102.     return(PBDirCreate(&pb, FALSE));
  103. }
  104. #endif    THINK_C
  105.